﻿using System;
using System.Text;

namespace XStudio.XCRF.Utilities.UTF8
{
    public static class UTF8Extention
    {
        /// <summary>
        /// 将字符串UTF8编码
        /// </summary>
        /// <param name="input">输入字符串</param>
        /// <returns></returns>
        public static string UTF8Encode(this string input)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(input);
            return BitConverter.ToString(bytes);
        }
        public static string UrlEncode(this string input)
        {
            StringBuilder sb = new StringBuilder();
            byte[] bytes = Encoding.UTF8.GetBytes(input); //默认System.Text.Encoding.Default.GetBytes(str)
            for (int i = 0; i < bytes.Length; i++)
            {
                sb.Append(@"%" + Convert.ToString(bytes[i], 16));
            }
            return (sb.ToString());
        }
    }
}
